import React from 'react'
import { fromJS } from 'immutable'
import * as constants from './constants'

const backList = (list) => ({ // 背景图
  type: constants.GET_BOOK_BACK_LIST,
  list: fromJS(list)
})
const getBackList = () => { // 背景图请求
  return async (dispatch) => {
    try {
      const res = await React.$api.get('/api/book/backgroundImage')
      if(res.success) {
        dispatch(backList(res.data))
      }
    } catch (err) {
      console.log(err)
    }
  }
}
const changeBackground = (list) =>({
  type: constants.CHANGE_BACK_LIST,
  list: fromJS(list)
})
export {
  getBackList,
  changeBackground,
}
